<template>
  <j-modal
    switchFullscreen
    :title='title'
    :width='500'
    :visible='visible'
    :maskClosable='false'
    :confirmLoading='confirmLoading'
    @ok='handleOk'
    @cancel='handleCancel'
    cancelText='关闭'>
    <template slot='footer'>
      <a-button @click='handleCancel'>取消</a-button>
      <a-button type='primary' @click='handleOk' v-if='!disableSubmit'>确认</a-button>
    </template>
    <a-spin :spinning='confirmLoading'>
      <a-form :form='form'>
        <a-row :gutter='24'>
          <a-col :md='24' :sm='24'>
            <a-form-item
              :labelCol='labelCol'
              :wrapperCol='wrapperCol'
              label='客户编号'
            >
              <a-input-search v-decorator="['customerCode',validatorRules.customerCode]"
                              readOnly enter-button @search="custSearch('superiorUser')" :disabled='disableSubmit' />
            </a-form-item>
          </a-col>
          <a-col :md='24' :sm='24'>
            <a-form-item
              :labelCol='labelCol'
              :wrapperCol='wrapperCol'
              label='客户名称'
            >
              <a-input disabled='true' v-decorator="['customerName']" />
            </a-form-item>
          </a-col>
<!--          <a-col :md='24' :sm='24'>-->
<!--            <a-form-item-->
<!--              :labelCol='labelCol'-->
<!--              :wrapperCol='wrapperCol'-->
<!--              label='经销商编号'-->
<!--              >-->
<!--              <a-input v-decorator="['customerCode',validatorRules.input ]" :disabled='disableSubmit' placeholder='经销商编号' />-->
<!--            </a-form-item>-->
<!--          </a-col>-->
<!--          <a-col :md="24" :sm="24">-->
<!--            <a-form-item-->
<!--              :labelCol="labelCol"-->
<!--              :wrapperCol="wrapperCol"-->
<!--              label="经销商名称"-->
<!--            >-->
<!--              <a-input v-decorator="['modelName']" :disabled='disableSubmit' placeholder='经销商名称' />-->
<!--            </a-form-item>-->
<!--          </a-col>-->
          <a-col :md='24' :sm='24'>
            <a-form-item
              :labelCol='labelCol'
              :wrapperCol='wrapperCol'
              label='起送量'
              >
              <a-input  :disabled='disableSubmit' placeholder='起送量' v-decorator="['liftingCapacity', ]" />
            </a-form-item>
          </a-col>
          <a-col :md='24' :sm='24'>
            <a-form-item
              :labelCol='labelCol'
              :wrapperCol='wrapperCol'
              label='起送日期'
              >
<!--              <a-select-->
<!--                v-decorator="[ 'deliveryDate']"-->
<!--                :disabled='disableSubmit'-->
<!--                placeholder='请选择'-->
<!--              >-->
<!--                <a-select-option v-for='(item,index) in option' :key='index' :value='item.dictDataCode'>-->
<!--                  {{item.dictDataDesc}}-->
<!--                </a-select-option>-->
<!--              </a-select>-->
<!--              <cn-multi-select-tag-->
<!--                v-decorator="['deliveryDate',]"-->
<!--                :placeholder="item.placeholder"-->
<!--                :options="option"-->
<!--                @change="changeSelect(option,'deliveryDate',$event,item.fun)"-->
<!--              ></cn-multi-select-tag>-->
<!--              <cn-multi-select-tag-->
<!--                type='a-select-multiple'-->
<!--                v-model="deliveryDate"-->
<!--                :options="option"-->
<!--                placeholder="请做出你的选择">-->
<!--              </cn-multi-select-tag>-->
              <cn-multi-select-tag
                type='select'
                style="width: 300px"
                dictCode="week_tyep"
                v-model='deliveryDate'
              ></cn-multi-select-tag>
            </a-form-item>
          </a-col>
          <a-col :md='24' :sm='24'>
            <a-form-item
              :labelCol='labelCol'
              :wrapperCol='wrapperCol'
              label='备注'
              >
              <a-textarea :disabled='disableSubmit' placeholder='备注'  v-decorator="['remarks', ]" />
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </a-spin>
    <proChose :name='modelname' ref='prochoose' v-bind='modalProps' @okbro='okbropro'></proChose>
  </j-modal>
</template>

<script>
import proChose from '@comp/cn-components/ProChose'
import CnMultiSelectTag from '@/components/dict/CnMultiSelectTag'
import { getAction, httpAction, postAction } from '@/api/manage'
import { pick } from 'lodash'


export default {
  name: 'carModelListModel',
  data() {
    return {
      title: '操作',
      visible: false,
      model: {},
      disableSubmit: false,
      labelCol: {
        xs: { span: 24 },
        sm: { span: 6 }
      },
      deliveryDate:'',
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      option: [
                  {
                    dictDataDesc: '星期一',
                    dictDataCode: '星期一'
                  },
                  {
                    dictDataDesc: '星期二',
                    dictDataCode: '星期二'
                  },
                  {
                    dictDataDesc: '星期三',
                    dictDataCode: '星期三'
                  },
                  {
                    dictDataDesc: '星期四',
                    dictDataCode: '星期四'
                  },
                  {
                    dictDataDesc: '星期五',
                    dictDataCode: '星期五'
                  }, {
                    dictDataDesc: '星期六',
                    dictDataCode: '星期六'
                  },
                  {
                    dictDataDesc: '星期日',
                    dictDataCode: '星期日'
                  },],
      confirmLoading: false,
      form: this.$form.createForm(this),
      validatorRules: {
        input: {
          rules: [
            { required: true, message: '' }
          ]
        },
      },
      addOrUpdateUrl: window._CONFIG['domianURL'] + '/liftingcapacityconfig/cnLiftingCapacityConfig/saveOrUpdate'
    }
  },
  components: {proChose,CnMultiSelectTag},
  created() {

  },
  methods: {
    okbropro(val, status, status2) {
      // console.log('数据',val)
      let objs = JSON.parse(JSON.stringify(val[0]))
      console.log('弹出框数据', objs)
      if (this.modelname == '客户') {
        this.form.setFieldsValue({
          customerCode: objs.custCode,
          customerName: objs.custName
        })
      } else if (this.modelname == '用户') {
        this.form.setFieldsValue({
          userCode: objs.userName,
          userName: objs.realName
        })
      }

    },
    add() {
      this.edit()
    },
    edit(record) {
      this.form.resetFields()
      this.model = Object.assign({}, record)
      this.deliveryDate=this.model.deliveryDate
      this.visible = true
      this.$nextTick(()=>{
        this.form.setFieldsValue(pick(this.model,Object.keys(this.model)))
      })
    },
    close(){
      this.handleCancel()
    },
    custSearch(status) {
      this.modelname = '客户'
      // console.log('数据',status)
      this.$refs.prochoose.rowKey = 'id'
      let formconfig = [
        {
          key: 'custCode',
          label: '客户编号'
        },
        {
          key: 'custName',
          label: '客户名称'
        }
      ]
      let tableconfig = {
        columns: [
          {
            title: '客户编号',
            align: 'center',
            dataIndex: 'custCode',
            width: 120,
            ellipsis: true
          },
          {
            title: '客户名称',
            align: 'center',
            dataIndex: 'custName',
            width: 120,
            ellipsis: true
          }
        ],
        list: window._CONFIG['domianURL'] + '/customerController/findPageList',
        multiple: false,
        columW: 8
      }
      let dataSource = []
      if (this.form.getFieldValue('superiorUser')) {
        dataSource = [{
          userName: this.form.getFieldValue('superiorUser'),
          realName: this.form.getFieldValue('realName')
        }]
      }
      this.name = '客户'
      this.$refs.prochoose.isorter = { permflag: 'purchase_customer_page_impl_add_cust' }
      this.$refs.prochoose.edit(formconfig, tableconfig, 'superiorUser', 'realsname', dataSource)
    },
    handleCancel() {
      this.visible = false
    },
    handleOk(){
      let vm = this
      this.form.validateFields((err,value) =>{
        if(!err){
          vm.confirmLoading = true
          let obj = Object.assign({},this.model,value)
          obj.deliveryDate=this.deliveryDate
          postAction(this.addOrUpdateUrl,obj).then(res=>{
            if(!res.success){
              vm.$message.error(res.message)
              return
            }
            vm.$emit('ok')
          }).finally(() => {
            vm.confirmLoading = false
          })
        }
      })
    },
  }
}
</script>

<style lang='less' scoped>
.info-line {
  display: flex;
  flex-direction: row;
}

.info-line:before {
  content: "";
  flex: 0.1;
  border-bottom: 1px solid #ebedee;
  margin: auto 4px;
}
.info-line:after {
  content: "";
  flex: 0.9;
  border-bottom: 2px solid #ebedee;
  margin: auto 4px;
}
</style>